package Thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class Demo29 {
    public static void main(String[] args) throws InterruptedException {
        //阻塞队列就相当于⼀个缓冲区，平衡了⽣产者和消费者的处理能⼒.(削峰填⾕)
        //使生产者和消费者解耦
        BlockingDeque<String> bq = new LinkedBlockingDeque<String>(10);
        for (int i = 0; i < 10; i++) {
            bq.put("" + i);
        }
        System.out.println("full");
        bq.put("22");  //如果已满在添加会进入阻塞状态 ，进入time waiting状态
        for (int i = 0; i < 10; i++) {
            System.out.println(bq.take());
        }
    }
}
